package com.application.mybatis;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.application.pojo.Auth;
import com.application.pojo.MenuMessage;
import com.application.pojo.OrderMessage;
import com.application.pojo.User;
import com.application.pojo.student;

public interface UserMybatis {
 @Select(value="select id as id , order_name as orderName , order_message as orderMessage ,order_type as orderType , order_date as orderDate from message_order ")
 public List<OrderMessage> selectOrder();
 @Select(value="select u.user_password from user_info u where user_name=#{name} ")
 public String selectByName(String name);
 @Select(value="select u.user_password as password , user_name as userName , user_sex as  sex from user_info u where user_name=#{name} ")
 public User selectUserByName(String name);
 @Update(value="update user_info set u.user_password =#{password} , user_sex = #{sex}  where user_name=#{userName} ")
 public User updateUserByName(User name);
 @Select(value="select r.id from user_info u join role r on r.user_id = u.id where u.user_name=#{name} ")
 public Long selectRoleByUserName(String name);
 @Select(value="select a.auth_name from auth a join role_auth ra on a.id = ra.auth_id join role r on r.id = ra.role_id  where r.id=#{id}")
 public List<String> selectAuth(Long id);
 
 @Insert(value="insert into message_order (order_name,,order_message,order_type) values (#{orderName},#{orderMessage},#{orderType})")
 public int insertOrder(OrderMessage message);
 @Delete(value="delete from message_order where id=#{id}")
 public int delOrder(Long id);
 @Update(value="update message_order set order_name=#{orderName},order_message=#{orderMessage},order_type=#{orderType} where id=#{id}")
 public int updtaOrder(OrderMessage message);
 @Insert(value="insert into auth (auth_name,auth_discribe) values (#{authName},#{authDiscribe})")
 public int insertModel(Auth auth);
 @Select(value="select count(*) from auth where auth_name = #{authName} and auth_discribe = #{authDiscribe}")
 public int selectModel(Auth auth);
 @Insert(value="insert into user_info (user_password,user_name) values(#{password},#{email})")
 public int insertUser(Map<String, String> map);
 
 @Select(value="select * from student")
 public List<student> selectStudent();
 @Insert(value="insert into student (name,birthday,sex,grade,address) values(#{name},#{birthday},#{sex},#{grade},#{address})")
 public int saveStudent(student s);
 @Delete(value="delete from student where id = #{id}")
 public int delStudent(Integer id);
 
 @Update(value="update student set name=#{name},birthday=#{birthday},sex=#{sex},grade=#{grade},address=#{address} where id=#{id}")
 public int editStudent(student s);
 @Select(value="select count(*) from student")
 public int countStudent();
 @Select(value="select count(*) from student where sex = 1")
 public int countStudentBoy();
 @Select(value="select count(*) from student where sex = 0")
 public int countStudentGirl();
 @Select(value="select * from student where id=#{id}")
 public student selectStudentById(int id);
 @Insert(value="insert into menu (menu_id,parent_id,collapsed,homepage,text,href,closeable) values (#{menuId},#{parentId},#{collapsed},#{homePage},#{text},#{href},#{closeable})")
 public int saveMenu(MenuMessage menuMessage);
 @Select(value="select count(*) from menu where menu_id = #{menuId}")
 public int exitMenu(String menuId);
 @Select(value="select menu_id as menuId,collapsed,homepage as homePage , text,href,closeable from menu where parent_id is null")
 public List<MenuMessage> selectRootMenu();
 @Select(value="select menu_id as menuId,collapsed,homepage as homePage , text,href,closeable from menu where parent_id = #{parentId}")
 public List<MenuMessage> selectSubMenu(String parentId);
 
}
